<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>实战课程推荐管理</title>
<link rel="stylesheet" href="/layui/css/layui.css"></link>
<link rel="stylesheet" href="/css/css.css"></link>
<style>
	.layui-table-body .layui-table-cell{
		height:50px;
		line-height: 50px;
	}
</style>
</head>
<body>

<div style="padding: 20px">
	        <span class="layui-breadcrumb">
			  <a>首页</a>
			  <a><cite>实战课程推荐管理</cite></a>
			</span>
	<div style="padding-top: 20px;">
		<div>
			<div>
				<button class="layui-btn layuiadmin-btn-list" data-type="batchdel" onclick="addSzkc()">添加实战课程推荐</button>
			</div>
		</div>
		<div>
			<table width="100%" id="courseListTable" ></table>
		</div>
	</div>
</div>

<script src="/layui/layui.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript">

    layui.use(['element','form','table'], function(){
        var form=layui.form;
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
        $ = layui.jquery; // 使用jquery
        table = layui.table;

        table.render({
            elem: '#courseListTable'
            ,url:'/admin/course/listAllSzkc'
            ,cols: [[
                {type:'checkbox'}
                ,{field:'id', width:60,title: 'ID'}
                ,{field:'imageName', width:200,title: '课程图片',templet:formatImageName}
                ,{field:'name', title: '课程名称',templet:formatName}
                ,{field:'type', width:100,title: '课程类型',templet:formatType}
                ,{field:'courseType', width:150,title: '课程类别',templet:formatCourseType}
                ,{field:'teacher', width:100,title: '授课老师',templet:formatTeacher}
                ,{field:'sort4', width:100,title: '排列序号'}
                ,{field:'action', width:200, title: '操作',align:'center',templet:formatAction}
            ]]
        });

    });


    function updateSzkc(id){
        layer.confirm('您确定要移除这条记录吗？', {
            title:"系统提示"
            ,btn: ['确定','取消'] //按钮
        }, function(){
            layer.closeAll('dialog');
            $.post("/admin/course/updateSzkc",{"id":id,"hktj":false},function(result){
                if(result.success){
                    layer.msg("移除成功！");
                    table.reload("courseListTable",{});
                }else{
                    layer.msg("删除失败，请联系管理员！");
                }
            },"json");
        }, function(){

        });
    }

    function addSzkc(){
        layer.open({
            type: 2,
            title: '添加实战课程推荐',
            area: ['800px', '600px'],
            content: '/admin/addSzkc.html' //iframe的url
        });
    }

    function updateSort(id){
        layer.open({
            type: 2,
            title: '修改实战课程推荐排列序号',
            area: ['500px', '300px'],
            content: '/admin/saveSzkc.html?id='+id //iframe的url
        });
    }






    function formatAction(d){
        return "<button class='layui-btn layui-btn-normal layui-btn-xs' onclick='updateSort("+d.id+")'><i class='layui-icon layui-icon-edit' ></i>修改排列序号</button><button class='layui-btn layui-btn-warm layui-btn-xs' onclick='updateSzkc("+d.id+")'><i class='layui-icon layui-icon-delete' ></i>移除</button>";
    }

    function formatImageName(d) {
        return "<img  src='/courseImages/"+d.imageName+"'/>";
    }

    function formatCourseType(d){
        return d.courseType.name;
    }

    function formatTeacher(d){
        return d.teacher.nickName;
	}

    function formatType(d) {
        if(d.type=='free'){
            return "实战课程";
		}else{
            return "<font color='red'>VIP课程</font>";
		}
    }

    function formatName(d) {
        return "<a target='_blank' href='/course/"+d.id+"'>"+d.name+"</a>";
    }




</script>
</body>
</html>